<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>从此再无生番</title>
    <style>
        /* 全局样式 */
        body {
            font-family: 'Arial', sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background: linear-gradient(135deg, #0f2027, #203a43, #2c5364); /* 渐变背景 */
            color: #f5f5f5;
        }

        /* 玻璃拟态容器 */
        .container {
            background: rgba(255, 255, 255, 0.1); /* 半透明背景 */
            backdrop-filter: blur(10px); /* 模糊效果 */
            -webkit-backdrop-filter: blur(10px); /* 兼容 Safari */
            border-radius: 15px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
            padding: 30px;
            width: 400px;
            text-align: center;
            border: 1px solid rgba(255, 255, 255, 0.2); /* 边框 */
        }

        h1 {
            font-size: 26px;
            margin-bottom: 20px;
            color: #ff9900; /* 标题颜色 */
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5); /* 字体阴影 */
        }

        label {
            display: block;
            margin: 10px 0 5px;
            font-weight: bold;
            color: #f5f5f5;
        }

        /* 输入框和选择框样式 */
        input[type="file"],
        select {
            width: 100%;
            padding: 12px;
            margin-bottom: 15px;
            border: none;
            border-radius: 8px;
            font-size: 14px;
            background: rgba(255, 255, 255, 0.2); /* 半透明背景 */
            color: #f5f5f5;
            outline: none;
            transition: all 0.3s ease;
        }

        input[type="file"]:hover,
        select:hover {
            background: rgba(255, 255, 255, 0.3); /* 悬停效果 */
        }

        /* 按钮样式 */
        button {
            width: 100%;
            padding: 12px;
            margin-top: 10px;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: bold;
            background: linear-gradient(45deg, #ff9900, #ff6600); /* 渐变按钮背景 */
            color: white;
            cursor: pointer;
            transition: transform 0.2s, box-shadow 0.2s;
        }

        button:hover {
            transform: translateY(-2px); /* 悬停时微微上移 */
            box-shadow: 0 4px 10px rgba(255, 153, 0, 0.5); /* 按钮阴影 */
        }

        button:active {
            transform: translateY(2px); /* 点击时下移 */
        }

        button:disabled {
            background: #888; /* 禁用时按钮颜色 */
            cursor: not-allowed;
        }

        /* 消息样式 */
        .message {
            margin-top: 20px;
            font-size: 16px;
            color: #00ff99; /* 成功消息颜色 */
        }

        .error {
            color: #ff4d4d; /* 错误消息颜色 */
        }

        /* 加载动画样式 */
        .loading {
            margin: 20px auto;
            border: 4px solid rgba(255, 255, 255, 0.2);
            border-top: 4px solid #ff9900;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% {
                transform: rotate(0deg);
            }
            100% {
                transform: rotate(360deg);
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>视频字幕处理</h1>
        <form id="uploadForm">
            <label for="file">上传视频文件</label>
            <input type="file" id="file" name="file" accept="video/*" required>

<!--            <label for="translate">选择翻译语言 (可选)</label>-->
<!--            <select id="translate" name="translate">-->
<!--                <option value="">不翻译</option>-->
<!--                <option value="en">英语</option>-->
<!--                <option value="zh">中文</option>-->
<!--                <option value="es">西班牙语</option>-->
<!--                <option value="fr">法语</option>-->
<!--                &lt;!&ndash; 可根据需求添加更多语言 &ndash;&gt;-->
<!--            </select>-->

            <label for="return_option">返回选项</label>
            <select id="return_option" name="return_option">
                <option value="video">返回带字幕的视频</option>
                <option value="subtitle">返回字幕文件</option>
            </select>

            <button type="submit" id="submitButton">开始处理</button>
        </form>
        <div class="loading" id="loading" style="display: none;"></div>
        <div class="message" id="message"></div>
    </div>

    <script>
        document.getElementById('uploadForm').addEventListener('submit', async function (e) {
            e.preventDefault();

            const formData = new FormData();
            const fileInput = document.getElementById('file');
            const translate = document.getElementById('translate').value;
            const returnOption = document.getElementById('return_option').value;
            const submitButton = document.getElementById('submitButton');
            const loadingDiv = document.getElementById('loading');
            const messageDiv = document.getElementById('message');

            if (fileInput.files.length === 0) {
                alert("请上传一个视频文件！");
                return;
            }

            formData.append('file', fileInput.files[0]);
            if (translate) {
                formData.append('translate', translate);
            }
            formData.append('return_option', returnOption);

            // 禁用按钮并显示加载动画
            submitButton.disabled = true;
            loadingDiv.style.display = 'block';
            messageDiv.textContent = '';
            messageDiv.classList.remove('error');

            try {
                const response = await fetch('/upload', {
                    method: 'POST',
                    body: formData
                });

                if (!response.ok) {
                    const errorData = await response.json();
                    throw new Error(errorData.error || "上传失败");
                }

                const data = await response.json();
                messageDiv.innerHTML = `
                    ${data.message}<br>
                    <a href="${data.download_url}" target="_blank">点击下载</a>
                `;
            } catch (error) {
                messageDiv.textContent = `发生错误: ${error.message}`;
                messageDiv.classList.add('error');
            } finally {
                // 恢复按钮状态并隐藏加载动画
                submitButton.disabled = false;
                loadingDiv.style.display = 'none';
            }
        });
    </script>
</body>
</html>
